//
//  MsgCenterController.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/16.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "MsgCenterController.h"
#import "MsgNavigationView.h"
#import "MsgCenterView.h"
#import "MsgDataCenter.h"

@interface MsgCenterController ()<MsgCenterViewDelegate, MsgNavigationViewDelegate>

@property (nonatomic, strong) MsgNavigationView *tabView;
@property (nonatomic, strong) MsgCenterView *centerView;
@property (nonatomic, strong) MsgDataCenter *dataCenter;

@end

@implementation MsgCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.baseTitle = @"消息中心";
    self.rightBtnTitle = @"返回";
    
    _dataCenter = [MsgDataCenter new];
    
    [self makeMsgCenterView];
  
}

- (void)makeMsgCenterView
{
    _tabView = [MsgNavigationView new];
    _tabView.delegate = self;
    [self.baseView addSubview:_tabView];
    [_tabView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(40);
        make.right.mas_equalTo(-40);
        make.height.mas_equalTo(44);
    }];
    
    _centerView = [MsgCenterView new];
    _centerView.delegate = self;
    [self.baseView addSubview:_centerView];
    [_centerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_tabView.mas_bottom).mas_offset(0);
        make.left.mas_equalTo(40);
        make.right.mas_equalTo(-40);
        make.bottom.mas_equalTo(-40);
    }];
}

- (void)slideCenterViewWithPage:(NSInteger)page
{
    [_tabView slideTabWithPage:page];
}

- (void)clickTabAtIndex:(NSInteger)index
{
    [_centerView scrollCollectionViewToIndex:index];
}

- (void)friendListRefreshData
{
    [self loadFriendListData];
}

- (void)loadFriendListData
{
    __weak typeof (self) weakSelf = self;
    [_dataCenter fetchMsgFriendListDataComplation:^(id data, NSString *error) {
        if (error == nil) {
            [weakSelf.centerView loadFriendListData:(NSArray *)data];
        }else{
            [YJProgressHud showErrorHud:error];
        }
    }];
}

- (void)didSelectAgreeWithFriend:(FriendModel *)friendModel
{
    
    [_dataCenter becomeFriend:friendModel complation:^(id data,NSString *error) {
        if (error == nil) {
            [[NSNotificationCenter defaultCenter] postNotificationName:BecomeFriendNotification object:nil];
            [YJProgressHud showSuccessHud:data];
        }else{
            [YJProgressHud showErrorHud:error];
        }
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
